%%{init: {'themeVariables': { 'fontSize': '12px'}}}%%
graph TD
    classDef path fill:#eee,stroke:#000,color:#000
    classDef plan fill:#fff,stroke-width:1px,color:#000
    classDef itemplan fill:#fff,stroke-width:2px,color:#000
    classDef unbatchedplan fill:#dff,stroke-width:1px,color:#000
    classDef sideeffectplan fill:#fcc,stroke-width:2px,color:#000
    classDef bucket fill:#f6f6f6,color:#000,stroke-width:2px,text-align:left

    subgraph "Buckets for queries/plugins/issue_2212"
    Bucket0("Bucket 0 (root)<br /><br />1: <br />ᐳ: 9, 10, 19, 45, 11, 29<br />2: PgSelect[8]<br />3: Connection[12]<br />4: ConnectionItems[14]"):::bucket
    Bucket1("Bucket 1 (nullableBoundary)<br />Deps: 12, 14, 19, 29, 11, 45<br /><br />ROOT Connectionᐸ8ᐳ[12]"):::bucket
    Bucket3("Bucket 3 (listItem)<br />Deps: 19, 29, 11, 45<br /><br />ROOT __Item{3}ᐸ14ᐳ[17]"):::bucket
    Bucket4("Bucket 4 (nullableBoundary)<br />Deps: 18, 19, 29, 11, 45<br /><br />ROOT PgSelectSingle{3}ᐸusersᐳ[18]<br />1: <br />ᐳ: 20, 23, 21, 22<br />2: LoadMany[25], LoadOne[37]<br />3: ApplyTransforms[32]<br />4: PgSelect[30]<br />5: Connection[35]"):::bucket
    Bucket5("Bucket 5 (subroutine)<br /><br />ROOT __Item{5}ᐸ25ᐳ[33]"):::bucket
    Bucket6("Bucket 6 (nullableBoundary)<br />Deps: 35, 45<br /><br />ROOT Connection{4}ᐸ30ᐳ[35]"):::bucket
    Bucket8("Bucket 8 (listItem)<br />Deps: 45<br /><br />ROOT __Item{8}ᐸ40ᐳ[43]"):::bucket
    Bucket9("Bucket 9 (nullableBoundary)<br />Deps: 44, 45<br /><br />ROOT PgSelectSingle{8}ᐸordersᐳ[44]"):::bucket
    end
    Bucket0 --> Bucket1
    Bucket1 --> Bucket3
    Bucket3 --> Bucket4
    Bucket4 --> Bucket5 & Bucket6
    Bucket6 --> Bucket8
    Bucket8 --> Bucket9

    %% plan dependencies
    Object11{{"Object[11∈0] ➊<br />ᐸ{pgSettings,withPgClient}ᐳ<br />Dependents: 3"}}:::plan
    Access9{{"Access[9∈0] ➊<br />ᐸ2.pgSettingsᐳ"}}:::plan
    Access10{{"Access[10∈0] ➊<br />ᐸ2.withPgClientᐳ"}}:::plan
    Access9 & Access10 --> Object11
    PgSelect8[["PgSelect[8∈0] ➊<br />ᐸusersᐳ<br />More deps:<br />- Object[11]"]]:::plan
    __Value2["__Value[2∈0] ➊<br />ᐸcontextᐳ"]:::plan
    __Value2 --> Access9
    __Value2 --> Access10
    Connection12[["Connection[12∈0] ➊<br />ᐸ8ᐳ"]]:::plan
    PgSelect8 --> Connection12
    ConnectionItems14[["ConnectionItems[14∈0] ➊"]]:::plan
    Connection12 --> ConnectionItems14
    Object29{{"Object[29∈0] ➊<br />ᐸ{pgExecutorContext}ᐳ<br />More deps:<br />- Object[11]"}}:::plan
    __Item17[/"__Item[17∈3]<br />ᐸ14ᐳ"\]:::itemplan
    ConnectionItems14 ==> __Item17
    PgSelectSingle18{{"PgSelectSingle[18∈3]<br />ᐸusersᐳ"}}:::plan
    __Item17 --> PgSelectSingle18
    List21{{"List[21∈4]<br />ᐸ19,20ᐳ<br />More deps:<br />- Constantᐸ'User'ᐳ[19]"}}:::plan
    PgClassExpression20{{"PgClassExpression[20∈4]<br />ᐸ__users__.”id”ᐳ"}}:::plan
    PgClassExpression20 --> List21
    LoadMany25[["LoadMany[25∈4]<br />ᐸloadᐳ"]]:::plan
    PgClassExpression20 & Object29 --> LoadMany25
    PgSelect30[["PgSelect[30∈4]<br />ᐸordersᐳ<br />More deps:<br />- Object[11]"]]:::plan
    ApplyTransforms32[["ApplyTransforms[32∈4]"]]:::plan
    ApplyTransforms32 --> PgSelect30
    LoadOne37[["LoadOne[37∈4]<br />ᐸloadᐳ"]]:::plan
    PgClassExpression20 & Object29 --> LoadOne37
    PgSelectSingle18 --> PgClassExpression20
    Lambda22{{"Lambda[22∈4]<br />ᐸbase64JSONEncodeᐳ"}}:::plan
    List21 --> Lambda22
    PgClassExpression23{{"PgClassExpression[23∈4]<br />ᐸ__users__.”username”ᐳ"}}:::plan
    PgSelectSingle18 --> PgClassExpression23
    LoadMany25 --> ApplyTransforms32
    Connection35[["Connection[35∈4]<br />ᐸ30ᐳ"]]:::plan
    PgSelect30 --> Connection35
    __Item33[/"__Item[33∈5]<br />ᐸ25ᐳ"\]:::itemplan
    LoadMany25 -.-> __Item33
    ConnectionItems40[["ConnectionItems[40∈6]"]]:::plan
    Connection35 --> ConnectionItems40
    __Item43[/"__Item[43∈8]<br />ᐸ40ᐳ"\]:::itemplan
    ConnectionItems40 ==> __Item43
    PgSelectSingle44{{"PgSelectSingle[44∈8]<br />ᐸordersᐳ"}}:::plan
    __Item43 --> PgSelectSingle44
    List47{{"List[47∈9]<br />ᐸ45,46ᐳ<br />More deps:<br />- Constantᐸ'Order'ᐳ[45]"}}:::plan
    PgClassExpression46{{"PgClassExpression[46∈9]<br />ᐸ__orders__.”id”ᐳ"}}:::plan
    PgClassExpression46 --> List47
    PgSelectSingle44 --> PgClassExpression46
    Lambda48{{"Lambda[48∈9]<br />ᐸbase64JSONEncodeᐳ"}}:::plan
    List47 --> Lambda48
    PgClassExpression49{{"PgClassExpression[49∈9]<br />ᐸ__orders__.”phone_e164”ᐳ"}}:::plan
    PgSelectSingle44 --> PgClassExpression49
    PgClassExpression50{{"PgClassExpression[50∈9]<br />ᐸ__orders__...unt_cents”ᐳ"}}:::plan
    PgClassExpression49 o--o PgClassExpression50

    %% define steps
    classDef bucket0 stroke:#696969
    class Bucket0,__Value2,PgSelect8,Access9,Access10,Object11,Connection12,ConnectionItems14,Object29 bucket0
    classDef bucket1 stroke:#00bfff
    class Bucket1 bucket1
    classDef bucket3 stroke:#ffa500
    class Bucket3,__Item17,PgSelectSingle18 bucket3
    classDef bucket4 stroke:#0000ff
    class Bucket4,PgClassExpression20,List21,Lambda22,PgClassExpression23,LoadMany25,PgSelect30,ApplyTransforms32,Connection35,LoadOne37 bucket4
    classDef bucket5 stroke:#7fff00
    class Bucket5,__Item33 bucket5
    classDef bucket6 stroke:#ff1493
    class Bucket6,ConnectionItems40 bucket6
    classDef bucket8 stroke:#dda0dd
    class Bucket8,__Item43,PgSelectSingle44 bucket8
    classDef bucket9 stroke:#ff0000
    class Bucket9,PgClassExpression46,List47,Lambda48,PgClassExpression49,PgClassExpression50 bucket9

